package com.android.yummycookies.model.theme;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import android.os.Parcel;
import android.os.Parcelable;

import com.android.yummycookies.commonInterface.ILoadableRessource;
import com.android.yummycookies.commonInterface.IScalableLoadableRessource;
import com.android.yummycookies.types.CookieType;

/**
 * Represente un Theme de jeu
 * 
 * @author julien
 * 
 */
public class Theme implements ILoadableRessource, IScalableLoadableRessource,
		Parcelable {

	private static final String TAG = Theme.class.getSimpleName();

	private int name;
	
	/** image du fond du plateau interactif */
	private int interactiveBoardBackground;
	/** tableau de types d'elements du plateau */
	private ArrayList<CookieType> cookieTypes = new ArrayList<CookieType>();

	public Theme(int name, int interactiveBoardBackground, ArrayList<CookieType> elemTypes) {
		this.name = name;
		this.interactiveBoardBackground = interactiveBoardBackground;
		this.cookieTypes = elemTypes;
	}

	public int getName() {
		return name;
	}
	
	public int getInteractiveBoardBackground() {
		return interactiveBoardBackground;
	}

	public ArrayList<CookieType> getElemTypes() {
		return cookieTypes;
	}
	
	/****************************************************
	 * ILoadableRessource
	 ****************************************************/

	@Override
	public Set<Integer> getBitmapsId() {
		HashSet<Integer> bitmapsId = new HashSet<Integer>();
		bitmapsId.add(interactiveBoardBackground);
//		for (CookieType ct : cookieTypes) {
//			bitmapsId.add(ct.getBitmapId());
//			bitmapsId.add(ct.getDestructionBitmapId());
//		}
		return bitmapsId;
	}

	/****************************************************
	 * IScalableLoadableRessource
	 ****************************************************/
	
	@Override
	public Set<Integer> getScalableBitmapsId() {
		HashSet<Integer> scalableBitmapsId = new HashSet<Integer>();
//		for (CookieType ct : cookieTypes) {
//			scalableBitmapsId.add(ct.getBitmapId());
//			scalableBitmapsId.add(ct.getDestructionBitmapId());
//		}
		return scalableBitmapsId;
	}

	/*****************************************************
	 * Gestion de l'interface Parcelable
	 *****************************************************/

	private Theme(Parcel in) {
		name = in.readInt();
		interactiveBoardBackground = in.readInt();
		int[] cookieTypes = in.createIntArray();
		CookieType[] allCookieTypes = CookieType.values();
		for (int ct : cookieTypes) {
			this.cookieTypes.add(allCookieTypes[ct]);
		}
	}

	public static final Parcelable.Creator<Theme> CREATOR = new Parcelable.Creator<Theme>() {
		public Theme createFromParcel(Parcel in) {
			return new Theme(in);
		}

		public Theme[] newArray(int size) {
			return new Theme[size];
		}
	};

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(name);
		dest.writeInt(interactiveBoardBackground);
		int[] cookieTypes = new int[this.cookieTypes.size()];
		int i = 0;
		for (CookieType ct : this.cookieTypes) {
			cookieTypes[i] = ct.ordinal();
			i++;
		}
		dest.writeIntArray(cookieTypes);

	}
}
